package com.nbsaas.boot.solution.data.entity;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "解决方案管理", model = "解决方案", menu = "1,57,60")
@Entity
@Table(name = "bs_solution")
public class Solution extends AbstractEntity {

    @SearchItem(label = "方案名称", name = "name")
    @FormField(title = "名称", sortNum = "2", grid = true, col = 22, width = "200")
    private String name;

    @SearchItem(label = "分类", name = "solutionCatalog", key = "solutionCatalog.id", operator = Operator.eq, type = InputType.select, classType = Long.class)
    @FieldName
    @FieldConvert
    @FormField(title = "解决方案分类", sortNum = "2", grid = true, col = 22, type = InputType.select, option = "solutionCatalog")
    @ManyToOne(fetch = FetchType.LAZY)
    private SolutionCatalog solutionCatalog;

    @Comment("是否在首页显示")
    @Dict(
            items = {
                    @DictItem(label = "否", value = 2),
                    @DictItem(label = "是", value = 1)
            }
    )
    private Integer showHome;

    @Comment("排序号")
    private Integer sortNum;

    @FormField(title = "图片", sortNum = "2", type = InputType.image, col = 22)
    private String logo;

    private String url;

    @FormField(title = "摘要", sortNum = "2", col = 22, type = InputType.textarea)
    private String introduce;


    @FormField(title = "阅读次数", sortNum = "2", col = 22, grid = true, ignore = true)
    private Long viewNum;

    @FormField(title = "创建人", sortNum = "2", col = 22, grid = true, ignore = true)
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    @FormField(title = "介绍", sortNum = "2", type = InputType.richText, col = 22)
    @Column(length = 8000)
    private String note;

    @SearchItem(label = "状态", name = "storeState", operator = Operator.eq, show = false)
    private StoreState storeState;
}
